(ns net.marigolda.test-ci-computs
	(:use clojure.test)
	(:use net.marigolda.ci-computs))

(deftest test-mid-result 
	(let [mike {:KillBill 5 :Superman 3 :SpongeBob 4.5 :Avatar 2} 
				ben {:KillBill 4 :Superman 2 :SpongeBob 2}
				a {:A 3 :B 2 :D 4}
				b {:A 5 :B 4 :C 3}]
		(is (= [12.5 8 54.25 24.0 35.0 3] (mid-result mike ben)))))

(deftest test-pc-score 
	(let [mike {"Lady in the Water" 2.5, "Snakes on a Plane" 3.5, "Just My Luck" 3.0, "Superman Returns" 3.5, "You, Me Dupree" 2.5, "The Night Listener" 3.0}
				ben {"Lady in the Water" 3.0, "Snakes on a Plane" 3.5, "Just My Luck" 1.5, "Superman Returns" 5.0, "The Night Listener" 3.0, "You, Me Dupree" 3.5}
				a {:A 2.5 :B 2 :D 4}
				b {:A 5 :B 4 :C 3}]
		(is (= 0.39605901719066977 (pc-score mike ben)))))

(deftest test-so-pc-score
  (is (= 0.39605901719066977 (so-pc-score {:user-id 1 :qs 2.5 :as 3.5 :ms 3.0 :ts 3.5 :ps 2.5 :rs 3.0} {:user-id 2 :qs 3.0 :as 3.5 :ms 1.5 :ts 5.0 :ps 3.5 :rs 3.0}))))

(deftest test-get-similarity-for
  (let [user1 {:user-id 1 :qs 2.5 :as 3.5 :ms 3.0 :ts 3.5 :ps 2.5 :rs 3.0}
        user2 {:user-id 2 :qs 3.0 :as 3.5 :ms 1.5 :ts 5.0 :ps 3.5 :rs 3.0}
        user3 {:user-id 3 :qs 3.5 :as 1.5 :ms 4.5 :ts 4.0 :ps 3.5 :rs 3.5}
        us {:1 user1 :2 user2 :3 user3}]
     (is (= {:2 0.39605901719066977 :3 -0.3286335345030998} (get-similarity-for user1 us)))))

(deftest test-max-val-pair
  (is (= [:c 5] (max-val-pair {:a 1 :b 2 :c 5 :d -2 :e 0}))))

(deftest test-get-similar-user-id
  (let [user1 {:user-id 1 :qs 2.5 :as 3.5 :ms 3.0 :ts 3.5 :ps 2.5 :rs 3.0}
        user2 {:user-id 2 :qs 3.0 :as 3.5 :ms 1.5 :ts 5.0 :ps 3.5 :rs 3.0}
        user3 {:user-id 3 :qs 3.5 :as 1.5 :ms 4.5 :ts 4.0 :ps 3.5 :rs 3.5}
        us {:1 user1 :2 user2 :3 user3}]
     (is (= :2 (get-similar-user-id user1 us)))
     (is (not (= :3 (get-similar-user-id user1 us))))))